home *** CD-ROM | disk | FTP | other *** search
/ ftp.hitl.washington.edu / ftp.hitl.washington.edu.tar / ftp.hitl.washington.edu / pub / people / tsoper / My Sample Apps / OpenGLSphereDemo / Form1.cs < prev    next >
Text File  |  2005-05-03  |  2KB  |  90 lines

  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using CsGL.OpenGL;
  5. public class SphereDemo : Form
  6. {
  7.     MyView view = new MyView();
  8.     public SphereDemo()
  9.     {
  10.         Text = "Sphere demo !";
  11.         view.Dock = DockStyle.Fill;
  12.         Controls.Add( view );
  13.     }
  14.     public static void Main()
  15.     {
  16.         SphereDemo di = new SphereDemo();
  17.         Application.Run( di );
  18.     }
  19. }
  20. class MyView : OpenGLControl
  21. {
  22.     public override void glDraw()
  23.     {
  24.         GL.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT ); // Clear Screen And Depth Buffer
  25.         GL.glShadeModel( GL.GL_SMOOTH );
  26.         /*GL.glBegin( GL.GL_QUADS );
  27.             GL.glColor3f(1,1,1);
  28.             //GL.glVertex3i( 100, 50, 0);
  29.             GL.glVertex3i( -10, -10, -20);
  30.             GL.glColor3f(1,0,1);
  31.             //GL.glVertex3i( 100, 130, 0 );
  32.             GL.glVertex3i( -10, 10, -30);
  33.             GL.glColor3f(1,1,0);
  34.             //GL.glVertex3i( 150, 130, 0 );
  35.             GL.glVertex3i( 10, 10, -5);
  36.             GL.glColor3f(0,1,1);
  37.             //GL.glVertex3i( 150, 50, 0 );
  38.             GL.glVertex3i( 10, -10, -3);
  39.         GL.glEnd();*/
  40.  
  41.         CsGL.OpenGL.GLUquadric q = GL.gluNewQuadric();
  42.         int radius;
  43.         radius = 1;
  44.  
  45.         GL.glTranslated(-2,-2,-2);
  46.         GL.gluQuadricDrawStyle(q,GL.GLU_FILL);
  47.         GL.glColor3f(1,1,1);
  48.         GL.gluSphere(q, radius, 20, 20);
  49.         GL.glTranslated(2,2,2);
  50.  
  51.         GL.glTranslated(2,-2,-2);
  52.         GL.gluQuadricDrawStyle(q,GL.GLU_LINE);
  53.         GL.glColor3f(1,0,0);
  54.         GL.gluSphere(q, radius, 20, 20);
  55.         GL.glTranslated(-2,2,2);
  56.  
  57.         GL.glTranslated(-2,2,-2);
  58.         GL.gluQuadricDrawStyle(q,GL.GLU_SILHOUETTE);
  59.         GL.glColor3f(0,1,0);
  60.         GL.gluSphere(q, radius, 20, 20);
  61.         GL.glTranslated(2,-2,2);
  62.  
  63.         GL.glTranslated(2,2,-2);
  64.         GL.gluQuadricDrawStyle(q,GL.GLU_POINT);
  65.         GL.glColor3f(0,0,1);
  66.         GL.gluSphere(q, radius, 20, 20);
  67.         GL.glTranslated(-2,-2,2);
  68.  
  69.         GL.glFlush();
  70.     }
  71.     protected override void InitGLContext()
  72.     {        
  73.         GL.glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
  74.         GL.glEnable( GL.GL_DEPTH_TEST);
  75.     }
  76.     protected override void OnSizeChanged(EventArgs e)
  77.     {
  78.         base.OnSizeChanged(e);
  79.         GL.glMatrixMode(GL.GL_PROJECTION);
  80.         GL.glLoadIdentity();
  81.         //GL.glOrtho( -20,20, -20,20, 0,1000);
  82.         GL.gluPerspective(90,1, 0.1,1000);
  83.  
  84.         
  85.         GL.glMatrixMode(GL.GL_MODELVIEW );
  86.         GL.glLoadIdentity();
  87.         GL.gluLookAt(0,0,3, 0,0,0, 0,1,0);
  88.     }
  89. }
  90.